import 'package:flutter/material.dart';

/// @class : BaseDialog
/// @date : 2021/08/27
/// @name : jhf
/// @description : 弹窗基类
///
class BaseNoListDialog extends StatefulWidget {
  ///child
  Widget child;

  ///圆角
  double shape;

  ///左右边距
  double horizontal = 25;
  ///弹框高度
  double? height = 300;
  BaseNoListDialog({
    Key? key,
    this.shape = 10,
    this.horizontal = 25,
    this.height = 300,
    required this.child,
  }) : super(key: key);

  @override
  State<BaseNoListDialog> createState() => _BaseNoListDialogState();
}

class _BaseNoListDialogState extends State<BaseNoListDialog> with TickerProviderStateMixin {
  ///动画加载控制器
  AnimationController? scaleController;
  Animation<double>? scaleAnimation;

  ///初始化动画控制器
  @override
  void initState() {
    super.initState();
    scaleController = AnimationController(
        vsync: this, duration: const Duration(milliseconds: 360));
    scaleAnimation = Tween(begin: 0.0, end: 1.0).animate(
        CurvedAnimation(parent: scaleController!, curve: Curves.easeIn));
  }

  @override
  Widget build(BuildContext context) {
    scaleController?.forward();
    return Material(

        ///透明样式
        type: MaterialType.transparency,
        ///dialog居中
        child: Center(
          child: Container(
              width: double.infinity,
              height: widget.height,
              margin: EdgeInsets.symmetric(
                  horizontal: widget.horizontal),
              child: Container(
                decoration: ShapeDecoration(
                  color: Colors.white,
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.all(
                      Radius.circular(widget.shape),
                    ),
                  ),
                ),
                child: widget.child,
              )
          ),
        )
    );
  }

  @override
  void dispose() {
    super.dispose();
    scaleController?.dispose();
  }
}
